//
//  ZJSCWishTypeView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/6/13.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJSCWishTypeView.h"

@implementation ZJSCWishTypeView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title
{
    self = [super initWithFrame:frame title:title];
    if (self) {
        
    }
    return self;
}

- (void)updataUI_dataArray:(NSArray *)dataArray selectString:(NSString *)selectString{
    for (id view in self.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            [(UIButton *)view removeFromSuperview];
        }
    }

    
    CGFloat maxLeft = self.titleLabel.right + 5 * [UIScreen zj_screenWScale];
    CGFloat space = 15 * [UIScreen zj_screenWScale];
    
    CGFloat imageH = [NSString heightWithTextFont:[UIFont titleTextFont]] + 8 * [UIScreen zj_screenHScale];
    for (int i = 0; i < dataArray.count; i++) {
        CGFloat imageW = [NSString sizeOfString:dataArray[i] font:[UIFont titleTextFontSize] width:self.width].width + 18 * [UIScreen zj_screenWScale];
       
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(maxLeft, 0, imageW, imageH)];
        button.centerY = self.titleLabel.centerY;
        
        button.layer.cornerRadius = imageH / 2.0;
        button.tag = i;
        button.titleLabel.font = [UIFont titleTextFont];
        [button setTitle:dataArray[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        
        maxLeft += imageW + space;
        if (!selectString && i == 0) {
            button.backgroundColor = [UIColor themeColor];
        }else if (selectString && i == [selectString integerValue]) {
            button.backgroundColor = [UIColor zj_colorWithHexString:@"f14241"];
          
        }else{
            button.backgroundColor = [UIColor themeColor];
        }
        [self addSubview:button];

    }
    
}




- (void)setSTATUS:(NSString *)STATUS{
    _STATUS = STATUS;
//    if ([STATUS isEqualToString:@"3"]) {
//
//        NSArray *array = @[@"未完成"];
//        [self updataUI_dataArray:@[array[0]] selectString:nil];
//    }else{
//        //-1审核未通过,1待审核,2审核通过,3已认领
//        NSArray *array = @[@"审核未通过",@"待审核",@"待认领",@"已认领",@"认领完成",@"已认领待审核"];
//        NSInteger number ;
//        if ([self.type isEqualToString:@"-1"]) {
//            number = 0;
//        }else{
//            number = [self.type integerValue];
//        }
//
//        [self updataUI_dataArray:@[array[number]] selectString:nil];
//
//    }
    
    
   
        //0 待认领,1 已解决,2正在解决,3暂无法解决
        NSArray *array = @[@"正在解决",@"正在解决",@"已解决",@"暂无法解决"];
        NSInteger number  = [STATUS integerValue];
    if (number == 3) {
         [self updataUI_dataArray:@[array[number]] selectString:@"0"];
    }else{
         [self updataUI_dataArray:@[array[number]] selectString:nil];
        
    }
    
    
}

@end
